package moelight.cat.moelight.Utils.SqlLiteUtils;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.util.Random;

public class SqliteDemo {
    private static SqliteHelper helper;

    public static void InitDataBase(Context context) {

        helper = SqliteManger.GetIntance(context);
        SQLiteDatabase database = helper.getReadableDatabase();
        new SqliteManger().ExecSQL(database, SqliteConstant.InitTabel);
        database.close();
    }

    public static void InsertData(Context context) {
        //  public  static  final  String InitTabel=String.format("create table %s(%s Integer primary key,%s Intger)",TABLE_NAME,ID,First);


        helper = SqliteManger.GetIntance(context);
        SQLiteDatabase database = helper.getReadableDatabase();
        new SqliteManger().ExecSQL(database, String.format(SqliteConstant.InsertData, "123"));
        database.close();
    }
    public static void UpdataData(Context context) {
        //  public  static  final  String InitTabel=String.format("create table %s(%s Integer primary key,%s Intger)",TABLE_NAME,ID,First);

        helper = SqliteManger.GetIntance(context);
        SQLiteDatabase database = helper.getWritableDatabase();
        new SqliteManger().ExecSQL(database, SqliteConstant.UpdateData);
        database.close();
    }

    public  static  void  InsertWithAPI(Context context){
        helper = SqliteManger.GetIntance(context);
        SQLiteDatabase database = helper.getWritableDatabase();
        ContentValues contentValues=new ContentValues();
      //  contentValues.put(SqliteConstant.ID,null);//自增主键可以忽略
        contentValues.put(SqliteConstant.First, new Random().nextInt());
        database.insert(SqliteConstant.TABLE_NAME,null,contentValues);
        database.close();


    }
    public  static  void  SelectDatabase(Context context){
        helper = SqliteManger.GetIntance(context);
        SQLiteDatabase database = helper.getWritableDatabase();
       String Sql = "select * from "+SqliteConstant.TABLE_NAME;//+ " where ID=?";
        Log.d("log",Sql);
        SqliteManger.SelectSql(database,Sql);


    }
}
